﻿<!--***********************************************************************************

   Extended WPF Toolkit

   Copyright (C) 2007-2013 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license 

   For more features, controls, and fast professional support,
   pick up the Plus Edition at http://xceed.com/wpf_toolkit

   Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids

  **********************************************************************************-->

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Xceed.Wpf.DataGrid"
                    xmlns:markup="clr-namespace:Xceed.Wpf.DataGrid.Markup"
                    xmlns:views="clr-namespace:Xceed.Wpf.DataGrid.Views"
                    xmlns:conv="clr-namespace:Xceed.Wpf.DataGrid.Converters">

   <ResourceDictionary.MergedDictionaries>

      <!-- Include the view independant, color-scheme independant, theme resources -->
      <markup:DataGridThemeResourceDictionary Source="Resources/Luna.Resources.xaml" />

      <!-- Include the view dependant, color-scheme independant, theme graphics -->
      <markup:DataGridThemeResourceDictionary Source="Resources/TableView.Luna.Graphics.xaml" />

      <!-- Include the view independant, color-scheme dependant, theme resources -->
      <markup:DataGridThemeResourceDictionary Source="Resources/Luna.metallic.Resources.xaml" />

      <!-- Include the standard grid element templates -->
      <markup:DataGridThemeResourceDictionary Source="../Common/TableflowView.GridElementTemplates.xaml" />

   </ResourceDictionary.MergedDictionaries>

   <!-- =================================================================== -->
   <!-- Resources specific to this View/Theme/ColorScheme                   -->
   <!-- =================================================================== -->

   <SolidColorBrush x:Key="gridLineBrush"
                    Color="Gray" />

   <SolidColorBrush x:Key="headerBackgroundBrush"
                    Color="#F9FAFD" />

   <SolidColorBrush x:Key="headerForegroundBrush"
                    Color="Black" />

   <SolidColorBrush x:Key="headerDelimiterDarkBorderBrush"
                    Color="#C6C7B5" />

   <SolidColorBrush x:Key="headerDelimiterLightBorderBrush"
                    Color="White" />

   <SolidColorBrush x:Key="headerHotBackgroundBrush"
                    Color="#FAF8F3" />

   <SolidColorBrush x:Key="headerPressedBorderBrush"
                    Color="#A5A597" />

   <SolidColorBrush x:Key="headerPressedLightInnerHighlightBrush"
                    Color="#D0D1C9" />

   <SolidColorBrush x:Key="headerPressedDarkInnerHighlightBrush"
                    Color="#C1C2B8" />

   <SolidColorBrush x:Key="headerPressedBackgroundBrush"
                    Color="#DEDFD8" />

   <SolidColorBrush x:Key="warningBackgroundBrush"
                    Color="#FFC400" />

   <SolidColorBrush x:Key="warningForegroundBrush"
                    Color="Black" />

   <LinearGradientBrush x:Key="headerHighlightVerticalBorderBrush"
                        StartPoint="0,0"
                        EndPoint="1,0">

      <GradientStop Offset="0"
                    Color="#F9FAFD" />

      <GradientStop Offset="1"
                    Color="#BDBECE" />

   </LinearGradientBrush>

   <LinearGradientBrush x:Key="headerHighlightHorizontalBorderBrush"
                        StartPoint="0,0"
                        EndPoint="0,1">

      <GradientStop Offset="0"
                    Color="#F9FAFD" />

      <GradientStop Offset="1"
                    Color="#BDBECE" />

   </LinearGradientBrush>

   <LinearGradientBrush x:Key="headerHotHighlightVerticalBorderBrush1"
                        StartPoint="0,0.5"
                        EndPoint="0.5,1">

      <GradientStop Offset="0"
                    Color="#FDE3AB" />

      <GradientStop Offset="1"
                    Color="#F9A900" />

   </LinearGradientBrush>

   <LinearGradientBrush x:Key="headerHotHighlightVerticalBackgroundBrush1"
                        StartPoint="0,0.5"
                        EndPoint="0.5,1">

      <GradientStop Offset="0"
                    Color="#FCE0A6" />

      <GradientStop Offset="1"
                    Color="#FCC247" />
   </LinearGradientBrush>

   <SolidColorBrush x:Key="headerHotHighlightVerticalBorderBrush2"
                    Color="#F9A900" />

   <SolidColorBrush x:Key="headerHotHighlightVerticalBackgroundBrush2"
                    Color="#FCC247" />

   <LinearGradientBrush x:Key="headerHotHighlightVerticalBorderBrush3"
                        StartPoint="0,0.5"
                        EndPoint="0.5,1">

      <GradientStop Offset="0"
                    Color="#F8A900" />

      <GradientStop Offset="1"
                    Color="#DE9600" />

   </LinearGradientBrush>

   <LinearGradientBrush x:Key="headerHotHighlightVerticalBackgroundBrush3"
                        StartPoint="0,0.5"
                        EndPoint="0.5,1">

      <GradientStop Offset="1"
                    Color="#DD9600" />

      <GradientStop Offset="0"
                    Color="#FCC247" />

   </LinearGradientBrush>

   <LinearGradientBrush x:Key="headerHotHighlightHorizontalBorderBrush1"
                        StartPoint="0,0.5"
                        EndPoint="1,0.5">

      <GradientStop Offset="0"
                    Color="#FDE3AB" />

      <GradientStop Offset="1"
                    Color="#F9A900" />

   </LinearGradientBrush>

   <LinearGradientBrush x:Key="headerHotHighlightHorizontalBackgroundBrush1"
                        StartPoint="0,0.5"
                        EndPoint="1,0.5">

      <GradientStop Offset="0"
                    Color="#FCE0A6" />

      <GradientStop Offset="1"
                    Color="#FCC247" />
   </LinearGradientBrush>

   <SolidColorBrush x:Key="headerHotHighlightHorizontalBorderBrush2"
                    Color="#F9A900" />

   <SolidColorBrush x:Key="headerHotHighlightHorizontalBackgroundBrush2"
                    Color="#FCC247" />

   <LinearGradientBrush x:Key="headerHotHighlightHorizontalBorderBrush3"
                        StartPoint="0,0.5"
                        EndPoint="1,0.5">

      <GradientStop Offset="0"
                    Color="#F8A900" />

      <GradientStop Offset="1"
                    Color="#DE9600" />

   </LinearGradientBrush>

   <LinearGradientBrush x:Key="headerHotHighlightHorizontalBackgroundBrush3"
                        StartPoint="0,0.5"
                        EndPoint="1,0.5">

      <GradientStop Offset="1"
                    Color="#DD9600" />

      <GradientStop Offset="0"
                    Color="#FCC247" />

   </LinearGradientBrush>

   <LinearGradientBrush x:Key="groupByControlBackgroundBrush"
                        StartPoint="0,0.5"
                        EndPoint="1,0.5">

      <GradientStop Offset="0"
                    Color="#ACA899" />
      <GradientStop Offset="1"
                    Color="#D6D3CD" />

   </LinearGradientBrush>

   <SolidColorBrush x:Key="groupByControlForegroundBrush"
                    Color="Black" />

   <!-- =================================================================== -->
   <!-- Templates specific to this View/Theme/ColorScheme                   -->
   <!-- =================================================================== -->

   <!--**************************
    * TEMPLATE: GroupNavigationControl
    ************************** -->
   <ControlTemplate x:Key="tableflowViewGroupNavigationControlTemplate"
                    TargetType="{x:Type local:GroupNavigationControl}">

      <Grid>
         <Border x:Name="outlineBorder"
                 BorderBrush="#808080"
                 BorderThickness="1"
                 Opacity="0">
            <Border.Background>
               <LinearGradientBrush StartPoint="0.5,0"
                                    EndPoint="0.5,1">
                  <GradientStop Color="#D0D1D2"
                                Offset="1" />
                  <GradientStop Color="#E8E9EB"
                                Offset="0" />
               </LinearGradientBrush>
            </Border.Background>
         </Border>

         <Grid>
            <Grid.ColumnDefinitions>
               <!-- Button part -->
               <ColumnDefinition Width="*" />

               <!-- Seperator part -->
               <ColumnDefinition Width="Auto" />

               <!-- Toggle button part -->
               <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Button x:Name="PART_Button"
                    Command="local:GroupNavigationButton.NavigateToGroup"
                    CommandParameter="{TemplateBinding Group}"
                    Content="{TemplateBinding Group}"
                    ContentTemplate="{TemplateBinding MainItemTemplate}"
                    ContentTemplateSelector="{TemplateBinding MainItemTemplateSelector}"
                    Foreground="{TemplateBinding Foreground}"
                    Focusable="False"
                    Grid.Column="0">
               <Button.Template>
                  <ControlTemplate TargetType="{x:Type Button}">
                     <Border Background="Transparent">
                        <ContentPresenter Margin="4,2,4,2" />
                     </Border>
                  </ControlTemplate>
               </Button.Template>
            </Button>

            <Border x:Name="seperator"
                    Grid.Column="1"
                    BorderThickness="0,0,1,0"
                    BorderBrush="{StaticResource headerDelimiterDarkBorderBrush}"
                    Margin="0,4,0,4"
                    Visibility="Hidden">
               <Border BorderThickness="0,0,1,0"
                       BorderBrush="{StaticResource headerDelimiterLightBorderBrush}" />
            </Border>

            <ToggleButton x:Name="PART_ToggleButton"
                          Focusable="False"
                          IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                          Grid.Column="2"
                          Foreground="{TemplateBinding Foreground}">
               <ToggleButton.Template>
                  <ControlTemplate>
                     <Border x:Name="toggleButtonBackground"
                             CornerRadius="0,6,6,0"
                             Background="Transparent">
                        <Path x:Name="Arrow"
                              Fill="{TemplateBinding Foreground}"
                              Margin="7,1,7,1"
                              HorizontalAlignment="Center"
                              VerticalAlignment="Center"
                              Data="M 0 0 L 4 4 L 0 8 Z"
                              Opacity="0.3" />
                     </Border>

                     <ControlTemplate.Triggers>
                        <Trigger Property="ToggleButton.IsMouseOver"
                                 Value="True">
                           <Setter TargetName="Arrow"
                                   Property="Opacity"
                                   Value="1" />
                        </Trigger>
                        <Trigger Property="ToggleButton.IsChecked"
                                 Value="True">
                           <Setter TargetName="Arrow"
                                   Property="Opacity"
                                   Value="1" />
                           <Setter TargetName="Arrow"
                                   Property="Margin"
                                   Value="5,1,5,1" />
                           <Setter TargetName="Arrow"
                                   Property="Data"
                                   Value="M 0 0 L 4 4 L 8 0 Z" />
                        </Trigger>
                     </ControlTemplate.Triggers>
                  </ControlTemplate>
               </ToggleButton.Template>
            </ToggleButton>
         </Grid>

         <Popup x:Name="PART_Popup"
                Placement="Bottom"
                IsOpen="{TemplateBinding IsDropDownOpen}"
                AllowsTransparency="True"
                Focusable="False"
                PopupAnimation="Slide">
            <Grid SnapsToDevicePixels="True"
                  MinWidth="{TemplateBinding ActualWidth}"
                  MaxHeight="{TemplateBinding MaxDropDownHeight}">
               <Border Background="White"
                       BorderBrush="Black"
                       BorderThickness="1"
                       TextElement.Foreground="Black">
                  <ScrollViewer CanContentScroll="True"
                                HorizontalScrollBarVisibility="Hidden"
                                VerticalScrollBarVisibility="Auto">
                     <!--<ItemsPresenter />-->
                     <VirtualizingStackPanel IsItemsHost="True" />
                  </ScrollViewer>
               </Border>
            </Grid>
         </Popup>
      </Grid>

      <ControlTemplate.Triggers>
         <Trigger Property="IsMouseOver"
                  Value="True">
            <Setter TargetName="outlineBorder"
                    Property="Opacity"
                    Value="1" />
            <Setter TargetName="seperator"
                    Property="Visibility"
                    Value="Visible" />
         </Trigger>

         <Trigger Property="IsDropDownOpen"
                  Value="True">
            <Setter TargetName="outlineBorder"
                    Property="Opacity"
                    Value="1" />
            <Setter TargetName="seperator"
                    Property="Visibility"
                    Value="Visible" />
         </Trigger>

         <Trigger SourceName="PART_Button"
                  Property="IsPressed"
                  Value="True">
            <Setter TargetName="outlineBorder"
                    Property="BorderBrush"
                    Value="#FF8C8A8C" />
            <Setter TargetName="outlineBorder"
                    Property="Background">
               <Setter.Value>
                  <LinearGradientBrush StartPoint="0.5,0"
                                       EndPoint="0.5,1">
                     <GradientStop Color="#D0D1D2"
                                   Offset="0" />
                     <GradientStop Color="#E8E9EB"
                                   Offset="1" />
                  </LinearGradientBrush>
               </Setter.Value>
            </Setter>
         </Trigger>
      </ControlTemplate.Triggers>
   </ControlTemplate>

   <!--**************************
    * TEMPLATE: GroupNavigationButton
    ************************** -->
   <ControlTemplate x:Key="tableflowViewGroupNavigationButtonTemplate"
                    TargetType="{x:Type local:GroupNavigationButton}">
      <Grid>
         <Border x:Name="border"
                 BorderBrush="#808080"
                 BorderThickness="1"
                 Opacity="0">
            <Border.Background>
               <LinearGradientBrush StartPoint="0.5,0"
                                    EndPoint="0.5,1">
                  <GradientStop Color="#D0D1D2"
                                Offset="1" />
                  <GradientStop Color="#E8E9EB"
                                Offset="0" />
               </LinearGradientBrush>
            </Border.Background>
         </Border>

         <ContentPresenter Margin="4,2,4,2" />
      </Grid>
      <ControlTemplate.Triggers>
         <Trigger Property="IsMouseOver"
                  Value="True">
            <Setter TargetName="border"
                    Property="Opacity"
                    Value="1" />
         </Trigger>
         <Trigger Property="IsPressed"
                  Value="True">
            <Setter TargetName="border"
                    Property="BorderBrush"
                    Value="#FF8C8A8C" />
            <Setter TargetName="border"
                    Property="Background">
               <Setter.Value>
                  <LinearGradientBrush StartPoint="0.5,0"
                                       EndPoint="0.5,1">
                     <GradientStop Color="#D0D1D2"
                                   Offset="0" />
                     <GradientStop Color="#E8E9EB"
                                   Offset="1" />
                  </LinearGradientBrush>
               </Setter.Value>
            </Setter>
         </Trigger>
      </ControlTemplate.Triggers>
   </ControlTemplate>

   <!--**************************
    * TEMPLATE: RowSelector 
    ************************** -->
   <ControlTemplate x:Key="tableflowViewRowSelectorTemplate"
                    TargetType="local:RowSelector">

      <!-- This Grid is used to position the resizer Thumb over the RowSelector -->
      <Grid>

         <!-- Since we use a very specific border arrangement to represent the RowSelector,
              we do not use the TemplatedParent's BorderBrush and BorderThickness properties.-->
         <Border x:Name="rootBorder"
                 Background="{TemplateBinding Background}">

            <Grid>

               <Border Padding="{TemplateBinding Padding}">

                  <ContentPresenter x:Name="contentPresenter"
                                    Content="{TemplateBinding Content}"
                                    ContentTemplate="{TemplateBinding ContentTemplate}"
                                    ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />

               </Border>

               <Border x:Name="isPressedDarkInnerHighlight"
                       BorderThickness="1,1,0,0">

                  <Border x:Name="isPressedLightInnerHighlight"
                          BorderThickness="1,1,0,0" />
               </Border>

            </Grid>

         </Border>

         <!-- This Grid is used to draw the gradient at the right side of the RowSelector.-->
         <Grid x:Name="rightBorder"
               Width="3"
               HorizontalAlignment="Right">

            <Grid.RowDefinitions>
               <RowDefinition Height="3" />
               <RowDefinition />
               <RowDefinition Height="3" />
            </Grid.RowDefinitions>

            <Border x:Name="topRightBorder"
                    Grid.Row="0"
                    Background="{StaticResource headerHighlightVerticalBorderBrush}" />

            <Border x:Name="middleRightBorder"
                    Grid.Row="1"
                    Background="{StaticResource headerHighlightVerticalBorderBrush}" />

            <Border x:Name="bottomRightBorder"
                    Grid.Row="2"
                    Background="{StaticResource headerHighlightVerticalBorderBrush}" />
         </Grid>

         <Rectangle x:Name="topBorder"
                    Fill="{StaticResource headerDelimiterLightBorderBrush}"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Top"
                    Height="1"
                    Margin="3,0,4,0" />

         <Rectangle x:Name="bottomBorder"
                    Fill="{StaticResource headerDelimiterDarkBorderBrush}"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Bottom"
                    Height="1"
                    Margin="3,0,4,0" />

         <!-- Thumb that is used to resize the Row. -->
         <Thumb x:Name="PART_RowResizerThumb"
                Style="{StaticResource invisibleThumbStyle}"
                VerticalAlignment="Bottom" />

      </Grid>

      <ControlTemplate.Triggers>

         <Trigger Property="IsMouseOver"
                  Value="True">

            <Setter TargetName="rootBorder"
                    Property="Background"
                    Value="{StaticResource headerHotBackgroundBrush}" />

            <!-- topRightBorder -->
            <Setter TargetName="topRightBorder"
                    Property="BorderThickness"
                    Value="1,0,1,1" />

            <Setter TargetName="topRightBorder"
                    Property="CornerRadius"
                    Value="0,3,0,0" />

            <Setter TargetName="topRightBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerHotHighlightVerticalBorderBrush1}" />

            <Setter TargetName="topRightBorder"
                    Property="Background"
                    Value="{StaticResource headerHotHighlightVerticalBackgroundBrush1}" />

            <!-- middleRightBorder -->
            <Setter TargetName="middleRightBorder"
                    Property="BorderThickness"
                    Value="1,0,1,0" />

            <Setter TargetName="middleRightBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerHotHighlightVerticalBorderBrush2}" />

            <Setter TargetName="middleRightBorder"
                    Property="Background"
                    Value="{StaticResource headerHotHighlightVerticalBackgroundBrush2}" />

            <!-- bottomRightBorder -->
            <Setter TargetName="bottomRightBorder"
                    Property="BorderThickness"
                    Value="0,1,1,1" />

            <Setter TargetName="bottomRightBorder"
                    Property="CornerRadius"
                    Value="0,0,3,0" />

            <Setter TargetName="bottomRightBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerHotHighlightVerticalBorderBrush3}" />

            <Setter TargetName="bottomRightBorder"
                    Property="Background"
                    Value="{StaticResource headerHotHighlightVerticalBackgroundBrush3}" />

            <Setter TargetName="topBorder"
                    Property="Visibility"
                    Value="Hidden" />

            <Setter TargetName="bottomBorder"
                    Property="Visibility"
                    Value="Hidden" />

         </Trigger>

         <Trigger Property="IsPressed"
                  Value="True">

            <Setter TargetName="rootBorder"
                    Property="Background"
                    Value="{StaticResource headerPressedBackgroundBrush}" />

            <Setter TargetName="rootBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerPressedBorderBrush}" />

            <Setter TargetName="rootBorder"
                    Property="BorderThickness"
                    Value="0,1,1,1" />

            <Setter TargetName="contentPresenter"
                    Property="Margin"
                    Value="3,0,0,0" />

            <Setter TargetName="rightBorder"
                    Property="Visibility"
                    Value="Hidden" />

            <Setter TargetName="isPressedLightInnerHighlight"
                    Property="BorderBrush"
                    Value="{StaticResource headerPressedLightInnerHighlightBrush}" />

            <Setter TargetName="isPressedDarkInnerHighlight"
                    Property="BorderBrush"
                    Value="{StaticResource headerPressedDarkInnerHighlightBrush}" />

         </Trigger>

      </ControlTemplate.Triggers>

   </ControlTemplate>

   <!--**************************
    * TEMPLATE: ColumnManagerCell 
    ************************** -->
   <conv:SortingDirectionToBooleanConverter x:Key="SortingDirectionToBooleanConverter" />

   <ControlTemplate x:Key="tableflowViewColumnManagerCellTemplate"
                    TargetType="local:ColumnManagerCell">

      <!-- This Grid is used to position the resizer Thumb over the ColumnManagerCell -->
      <Grid>

         <Border BorderBrush="{TemplateBinding BorderBrush}"
                 BorderThickness="{TemplateBinding BorderThickness}">

            <Grid>

               <DockPanel>
                  <Border x:Name="thumbToggleBackgroundBorder"
                          DockPanel.Dock="Right">

                     <Grid>

                        <Border x:Name="toggleDelimeterBorder"
                                BorderBrush="{StaticResource headerDelimiterDarkBorderBrush}"
                                BorderThickness="1,0,0,0"
                                Margin="0,4,0,4"
                                Background="Transparent"
                                Visibility="Collapsed">

                           <Border x:Name="toggleDelimeterBorder2"
                                   BorderBrush="{StaticResource headerDelimiterLightBorderBrush}"
                                   BorderThickness="1,0,0,0"
                                   Margin="0,0,0,0"
                                   Background="Transparent"
                                   Visibility="Collapsed">

                           </Border>

                        </Border>

                        <ToggleButton x:Name="toggleButton"
                                      VerticalAlignment="Stretch"
                                      Focusable="False"
                                      Visibility="Collapsed"
                                      Margin="2,0,0,0"
                                      Opacity="0.5" />
                     </Grid>
                  </Border>

                  <!-- Since we use a very specific border arrangement to represent the ColumnManagerCell,
              we do not use the TemplatedParent's BorderBrush and BorderThickness properties.-->
                  <Border x:Name="rootBorder"
                          Background="{TemplateBinding Background}">

                     <Grid>

                        <Border Padding="{TemplateBinding Padding}">

                           <Grid x:Name="contentPanel"
                                 HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                 VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                              <Grid.ColumnDefinitions>
                                 <ColumnDefinition Width="*" />
                                 <ColumnDefinition Width="Auto" />
                                 <ColumnDefinition Width="Auto" />
                              </Grid.ColumnDefinitions>

                              <!-- Same ContentPresenter as in the base Cell Template. -->
                              <local:CellContentPresenter x:Name="PART_CellContentPresenter"
                                                          Grid.Column="0" />

                              <!-- ContentPresenter that is used to display the sort glyph.
                                      We explicitely set its Content property to Null to prevent the XAML parser
                                      from implicitely setting it to its TemplatedParent's Content. -->
                              <ContentPresenter x:Name="sortGlyphPresenter"
                                                Content="{x:Null}"
                                                ContentTemplate="{x:Null}"
                                                Grid.Column="1" />
                           </Grid>
                        </Border>

                     </Grid>

                  </Border>
               </DockPanel>

               <!-- This Grid is used to draw the gradient at the right side of the RowSelector.-->
               <Grid x:Name="bottomBorder"
                     Height="3"
                     IsHitTestVisible="False"
                     Grid.ColumnSpan="3"
                     VerticalAlignment="Bottom">

                  <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="8" />
                     <ColumnDefinition />
                     <ColumnDefinition Width="10" />
                  </Grid.ColumnDefinitions>

                  <Border x:Name="leftBottomBorder"
                          Grid.Column="0"
                          Background="{StaticResource headerHighlightHorizontalBorderBrush}" />

                  <Border x:Name="middleBottomBorder"
                          Grid.Column="1"
                          Background="{StaticResource headerHighlightHorizontalBorderBrush}" />

                  <Border x:Name="rightBottomBorder"
                          Grid.Column="2"
                          Background="{StaticResource headerHighlightHorizontalBorderBrush}" />
               </Grid>

               <Border x:Name="rightBorder"
                       BorderThickness="0,0,1,0"
                       BorderBrush="{StaticResource headerDelimiterLightBorderBrush}"
                       Background="{StaticResource headerDelimiterDarkBorderBrush}"
                       Margin="0,3,0,4"
                       Grid.ColumnSpan="3"
                       VerticalAlignment="Stretch"
                       HorizontalAlignment="Right"
                       Width="2" />

               <Border x:Name="rightPressedBorder"
                       BorderThickness="0,0,1,0"
                       BorderBrush="{StaticResource headerPressedBorderBrush}"
                       Visibility="Hidden"
                       VerticalAlignment="Stretch"
                       HorizontalAlignment="Right"
                       Width="1" />

               <Border x:Name="isPressedDarkInnerHighlight"
                       BorderThickness="1,1,0,0"
                       Margin="1,0,1,0">

                  <Border x:Name="isPressedLightInnerHighlight"
                          BorderThickness="1,1,0,0" />

               </Border>

            </Grid>

         </Border>

         <!-- Thumb that is used to resize the Column. -->
         <Thumb x:Name="PART_ColumnResizerThumbLeft"
                Style="{StaticResource invisibleThumbStyle}"
                Width="6"
                HorizontalAlignment="Left" />

         <!-- Thumb that is used to resize the Column. -->
         <Thumb x:Name="PART_ColumnResizerThumb"
                Style="{StaticResource invisibleThumbStyle}"
                Width="6"
                HorizontalAlignment="Right" />

      </Grid>

      <ControlTemplate.Triggers>

         <!-- The following triggers allows the content to correctly align to the center when the mouse is over the ColumnManagerCell and the HorizontalContentAlignment is Center -->
         <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
               <Condition Value="Visible"
                          Binding="{Binding ElementName=toggleButton, Path=Visibility}" />
               <Condition Value="Center"
                          Binding="{Binding RelativeSource={RelativeSource Self},
                        Path=HorizontalContentAlignment}" />
            </MultiDataTrigger.Conditions>

            <Setter TargetName="PART_CellContentPresenter"
                    Property="Margin"
                    Value="18,0,0,0" />
         </MultiDataTrigger>

         <!-- Trigger related to the filteringToggleButton-->
         <Trigger SourceName="toggleButton"
                  Property="IsMouseOver"
                  Value="True">

            <Setter TargetName="toggleButton"
                    Property="Opacity"
                    Value="1" />
         </Trigger>

         <Trigger Property="IsMouseOver"
                  Value="True">

            <Setter TargetName="rootBorder"
                    Property="Background"
                    Value="{StaticResource headerHotBackgroundBrush}" />

            <Setter TargetName="thumbToggleBackgroundBorder"
                    Property="Background"
                    Value="{StaticResource headerHotBackgroundBrush}" />

            <!-- leftBottomBorder -->
            <Setter TargetName="leftBottomBorder"
                    Property="BorderThickness"
                    Value="1,1,0,1" />

            <Setter TargetName="leftBottomBorder"
                    Property="CornerRadius"
                    Value="0,0,0,3" />

            <Setter TargetName="leftBottomBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerHotHighlightHorizontalBorderBrush1}" />

            <Setter TargetName="leftBottomBorder"
                    Property="Background"
                    Value="{StaticResource headerHotHighlightHorizontalBackgroundBrush1}" />

            <!-- middleBottomBorcharder -->
            <Setter TargetName="middleBottomBorder"
                    Property="BorderThickness"
                    Value="0,1,0,1" />

            <Setter TargetName="middleBottomBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerHotHighlightHorizontalBorderBrush2}" />

            <Setter TargetName="middleBottomBorder"
                    Property="Background"
                    Value="{StaticResource headerHotHighlightHorizontalBackgroundBrush2}" />

            <!-- rightBottomBorder -->
            <Setter TargetName="rightBottomBorder"
                    Property="BorderThickness"
                    Value="0,1,1,1" />

            <Setter TargetName="rightBottomBorder"
                    Property="CornerRadius"
                    Value="0,0,3,0" />

            <Setter TargetName="rightBottomBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerHotHighlightHorizontalBorderBrush3}" />

            <Setter TargetName="rightBottomBorder"
                    Property="Background"
                    Value="{StaticResource headerHotHighlightHorizontalBackgroundBrush3}" />

            <Setter TargetName="rightBorder"
                    Property="Visibility"
                    Value="Hidden" />

         </Trigger>

         <Trigger Property="IsPressed"
                  Value="True">

            <Setter TargetName="rootBorder"
                    Property="Background"
                    Value="{StaticResource headerPressedBackgroundBrush}" />

            <Setter TargetName="rootBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerPressedBorderBrush}" />

            <Setter TargetName="thumbToggleBackgroundBorder"
                    Property="Background"
                    Value="{StaticResource headerPressedBackgroundBrush}" />

            <Setter TargetName="rightBorder"
                    Property="Visibility"
                    Value="Hidden" />

            <Setter TargetName="rootBorder"
                    Property="BorderThickness"
                    Value="1,0,0,0" />

            <Setter TargetName="contentPanel"
                    Property="Margin"
                    Value="1,1,-1,-1" />

            <Setter TargetName="bottomBorder"
                    Property="Visibility"
                    Value="Hidden" />

            <Setter TargetName="thumbToggleBackgroundBorder"
                    Property="BorderThickness"
                    Value="0,1,0,0" />

            <Setter TargetName="rightPressedBorder"
                    Property="Visibility"
                    Value="Visible" />

            <Setter TargetName="thumbToggleBackgroundBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerPressedDarkInnerHighlightBrush}" />

            <Setter TargetName="isPressedLightInnerHighlight"
                    Property="BorderBrush"
                    Value="{StaticResource headerPressedLightInnerHighlightBrush}" />

            <Setter TargetName="isPressedDarkInnerHighlight"
                    Property="BorderBrush"
                    Value="{StaticResource headerPressedDarkInnerHighlightBrush}" />

         </Trigger>

         <!-- The following 2 triggers allow to display the appropriate Sort Glyph
              depending on the ParentColumn's SortDirection. -->

         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=ParentColumn.SortDirection}"
                      Value="Ascending">

            <Setter TargetName="sortGlyphPresenter"
                    Property="ContentPresenter.ContentTemplate"
                    Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).AscendingSortGlyph}" />

            <Setter TargetName="sortGlyphPresenter"
                    Property="Margin"
                    Value="6,0,0,0" />

         </DataTrigger>

         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=ParentColumn.SortDirection}"
                      Value="Descending">

            <Setter TargetName="sortGlyphPresenter"
                    Property="ContentPresenter.ContentTemplate"
                    Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).DescendingSortGlyph}" />

            <Setter TargetName="sortGlyphPresenter"
                    Property="Margin"
                    Value="6,0,0,0" />

         </DataTrigger>

         <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
               <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=ParentColumn.HasFixedWidth}"
                          Value="True" />

               <!-- Don't disable resizing if ColumnStretching can be disabled by an 
                    end-user resize. -->
               <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).RemoveColumnStretchingOnResize}"
                          Value="False" />
            </MultiDataTrigger.Conditions>

            <Setter TargetName="PART_ColumnResizerThumb"
                    Property="IsEnabled"
                    Value="False" />
         </MultiDataTrigger>

         <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
               <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=ParentColumn.PreviousVisibleColumn.HasFixedWidth}"
                          Value="True" />

               <!-- Don't disable resizing if ColumnStretching can be disabled by an 
                    end-user resize. -->
               <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).RemoveColumnStretchingOnResize}"
                          Value="False" />
            </MultiDataTrigger.Conditions>

            <Setter TargetName="PART_ColumnResizerThumbLeft"
                    Property="IsEnabled"
                    Value="False" />
         </MultiDataTrigger>

         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=ParentRow.AllowColumnResize}"
                      Value="False">
            <Setter TargetName="PART_ColumnResizerThumb"
                    Property="IsEnabled"
                    Value="False" />
            <Setter TargetName="PART_ColumnResizerThumbLeft"
                    Property="IsEnabled"
                    Value="False" />
         </DataTrigger>

         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=ParentColumn.Visible}"
                      Value="False">
            <Setter Property="Visibility"
                    Value="Collapsed" />
         </DataTrigger>

      </ControlTemplate.Triggers>

   </ControlTemplate>

   <!--**************************
    * TEMPLATE: GroupByItem 
    ************************** -->
   <ControlTemplate x:Key="tableflowViewGroupByItemTemplate"
                    TargetType="local:GroupByItem">

      <Grid>

         <Border x:Name="rootBorder"
                 BorderBrush="{TemplateBinding BorderBrush}"
                 BorderThickness="{TemplateBinding BorderThickness}"
                 Background="{TemplateBinding Background}">

            <Grid>

               <Border Padding="{TemplateBinding Padding}">

                  <!-- This StackPanel is used to layout the ContentPresenter and the Sort Glyph (when present). -->
                  <StackPanel x:Name="contentPanel"
                              Orientation="Horizontal">

                     <!-- Same ContentPresenter as in the base Cell Template. -->
                     <ContentPresenter Content="{TemplateBinding Content}"
                                       ContentTemplate="{TemplateBinding ContentTemplate}"
                                       ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                       HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                       VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />

                     <!-- ContentPresenter that is used to display the sort glyph.
                          We explicitely set its Content property to Null to prevent the XAML parser
                          from implicitely setting it to its TemplatedParent's Content. -->
                     <ContentPresenter x:Name="sortGlyphPresenter"
                                       Content="{x:Null}"
                                       ContentTemplate="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).AscendingSortGlyph}"
                                       Margin="6,0,0,0"
                                       Visibility="Hidden" />

                  </StackPanel>

               </Border>

               <Border x:Name="isPressedDarkInnerHighlight"
                       BorderThickness="1,1,0,0">

                  <Border x:Name="isPressedLightInnerHighlight"
                          BorderThickness="1,1,0,0" />
               </Border>

               <!-- This Grid is used to draw the gradient at the right side of the RowSelector.-->
               <Grid x:Name="bottomBorder"
                     Height="3"
                     VerticalAlignment="Bottom">

                  <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="8" />
                     <ColumnDefinition />
                     <ColumnDefinition Width="10" />
                  </Grid.ColumnDefinitions>

                  <Border x:Name="leftBottomBorder"
                          Grid.Column="0" />

                  <Border x:Name="middleBottomBorder"
                          Grid.Column="1" />

                  <Border x:Name="rightBottomBorder"
                          Grid.Column="2" />
               </Grid>

            </Grid>

         </Border>

      </Grid>

      <ControlTemplate.Triggers>

         <Trigger Property="IsMouseOver"
                  Value="True">

            <Setter TargetName="rootBorder"
                    Property="Background"
                    Value="{StaticResource headerHotBackgroundBrush}" />

            <!-- leftBottomBorder -->
            <Setter TargetName="leftBottomBorder"
                    Property="BorderThickness"
                    Value="1,1,0,1" />

            <Setter TargetName="leftBottomBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerHotHighlightHorizontalBorderBrush1}" />

            <Setter TargetName="leftBottomBorder"
                    Property="Background"
                    Value="{StaticResource headerHotHighlightHorizontalBackgroundBrush1}" />

            <!-- middleBottomBorder -->
            <Setter TargetName="middleBottomBorder"
                    Property="BorderThickness"
                    Value="0,1,0,1" />

            <Setter TargetName="middleBottomBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerHotHighlightHorizontalBorderBrush2}" />

            <Setter TargetName="middleBottomBorder"
                    Property="Background"
                    Value="{StaticResource headerHotHighlightHorizontalBackgroundBrush2}" />

            <!-- rightBottomBorder -->
            <Setter TargetName="rightBottomBorder"
                    Property="BorderThickness"
                    Value="0,1,1,1" />

            <Setter TargetName="rightBottomBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerHotHighlightHorizontalBorderBrush3}" />

            <Setter TargetName="rightBottomBorder"
                    Property="Background"
                    Value="{StaticResource headerHotHighlightHorizontalBackgroundBrush3}" />

         </Trigger>

         <Trigger Property="IsPressed"
                  Value="True">

            <Setter TargetName="rootBorder"
                    Property="Background"
                    Value="{StaticResource headerPressedBackgroundBrush}" />

            <Setter TargetName="rootBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerPressedBorderBrush}" />

            <Setter TargetName="rootBorder"
                    Property="BorderThickness"
                    Value="1,0,1,1" />

            <Setter TargetName="contentPanel"
                    Property="Margin"
                    Value="1,1,-1,0" />

            <Setter TargetName="bottomBorder"
                    Property="Visibility"
                    Value="Hidden" />

            <Setter TargetName="isPressedLightInnerHighlight"
                    Property="BorderBrush"
                    Value="{StaticResource headerPressedLightInnerHighlightBrush}" />

            <Setter TargetName="isPressedDarkInnerHighlight"
                    Property="BorderBrush"
                    Value="{StaticResource headerPressedDarkInnerHighlightBrush}" />

         </Trigger>

         <!-- The following 2 triggers allow to display the appropriate Sort Glyph
              depending on the ParentColumn's SortDirection. -->

         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=SortDirection}"
                      Value="Ascending">

            <Setter TargetName="sortGlyphPresenter"
                    Property="Visibility"
                    Value="Visible" />

         </DataTrigger>

         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=SortDirection}"
                      Value="Descending">

            <Setter TargetName="sortGlyphPresenter"
                    Property="ContentPresenter.ContentTemplate"
                    Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).DescendingSortGlyph}" />

            <Setter TargetName="sortGlyphPresenter"
                    Property="Visibility"
                    Value="Visible" />

         </DataTrigger>

      </ControlTemplate.Triggers>

   </ControlTemplate>

   <!--**************************
    * TEMPLATE: HierarchicalGroupByControlNode
    ************************** -->
   <ControlTemplate x:Key="tableflowViewHierarchicalGroupByControlNodeTemplate"
                    TargetType="local:HierarchicalGroupByControlNode">

      <StackPanel Orientation="Horizontal"
                  Background="{TemplateBinding Background}">

         <Border BorderBrush="{StaticResource gridLineBrush}"
                 Background="#55FFFFFF"
                 BorderThickness="1"
                 VerticalAlignment="Top"
                 HorizontalAlignment="Center">

            <TextBlock x:Name="titleTextBlock"
                       Text="{TemplateBinding Title}"
                       Margin="2" />
         </Border>

         <ItemsPresenter />
      </StackPanel>

   </ControlTemplate>

   <!--**************************
    * TEMPLATE: HierarchicalGroupByItem
    ************************** -->
   <ControlTemplate x:Key="tableflowViewHierarchicalGroupByItemTemplate"
                    TargetType="local:HierarchicalGroupByItem">

      <Grid>

         <Border x:Name="rootBorder"
                 BorderBrush="{TemplateBinding BorderBrush}"
                 BorderThickness="{TemplateBinding BorderThickness}"
                 Background="{TemplateBinding Background}">

            <Grid>

               <Border Padding="{TemplateBinding Padding}">

                  <!-- This StackPanel is used to layout the ContentPresenter and the Sort Glyph (when present). -->
                  <StackPanel x:Name="contentPanel"
                              Orientation="Horizontal">

                     <!-- Same ContentPresenter as in the base Cell Template. -->
                     <ContentPresenter Content="{TemplateBinding Content}"
                                       ContentTemplate="{TemplateBinding ContentTemplate}"
                                       ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                       HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                       VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />

                     <!-- ContentPresenter that is used to display the sort glyph.
                          We explicitely set its Content property to Null to prevent the XAML parser
                          from implicitely setting it to its TemplatedParent's Content. -->
                     <ContentPresenter x:Name="sortGlyphPresenter"
                                       Content="{x:Null}"
                                       ContentTemplate="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).AscendingSortGlyph}"
                                       Margin="6,0,0,0"
                                       Visibility="Hidden" />

                  </StackPanel>

               </Border>

               <Border x:Name="isPressedDarkInnerHighlight"
                       BorderThickness="1,1,0,0">

                  <Border x:Name="isPressedLightInnerHighlight"
                          BorderThickness="1,1,0,0" />
               </Border>

               <!-- This Grid is used to draw the gradient at the right side of the RowSelector.-->
               <Grid x:Name="bottomBorder"
                     Height="3"
                     VerticalAlignment="Bottom">

                  <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="8" />
                     <ColumnDefinition />
                     <ColumnDefinition Width="10" />
                  </Grid.ColumnDefinitions>

                  <Border x:Name="leftBottomBorder"
                          Grid.Column="0" />

                  <Border x:Name="middleBottomBorder"
                          Grid.Column="1" />

                  <Border x:Name="rightBottomBorder"
                          Grid.Column="2" />
               </Grid>

            </Grid>

         </Border>

      </Grid>

      <ControlTemplate.Triggers>

         <Trigger Property="IsMouseOver"
                  Value="True">

            <Setter TargetName="rootBorder"
                    Property="Background"
                    Value="{StaticResource headerHotBackgroundBrush}" />

            <!-- leftBottomBorder -->
            <Setter TargetName="leftBottomBorder"
                    Property="BorderThickness"
                    Value="1,1,0,1" />

            <Setter TargetName="leftBottomBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerHotHighlightHorizontalBorderBrush1}" />

            <Setter TargetName="leftBottomBorder"
                    Property="Background"
                    Value="{StaticResource headerHotHighlightHorizontalBackgroundBrush1}" />

            <!-- middleBottomBorder -->
            <Setter TargetName="middleBottomBorder"
                    Property="BorderThickness"
                    Value="0,1,0,1" />

            <Setter TargetName="middleBottomBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerHotHighlightHorizontalBorderBrush2}" />

            <Setter TargetName="middleBottomBorder"
                    Property="Background"
                    Value="{StaticResource headerHotHighlightHorizontalBackgroundBrush2}" />

            <!-- rightBottomBorder -->
            <Setter TargetName="rightBottomBorder"
                    Property="BorderThickness"
                    Value="0,1,1,1" />

            <Setter TargetName="rightBottomBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerHotHighlightHorizontalBorderBrush3}" />

            <Setter TargetName="rightBottomBorder"
                    Property="Background"
                    Value="{StaticResource headerHotHighlightHorizontalBackgroundBrush3}" />

         </Trigger>

         <Trigger Property="IsPressed"
                  Value="True">

            <Setter TargetName="rootBorder"
                    Property="Background"
                    Value="{StaticResource headerPressedBackgroundBrush}" />

            <Setter TargetName="rootBorder"
                    Property="BorderBrush"
                    Value="{StaticResource headerPressedBorderBrush}" />

            <Setter TargetName="rootBorder"
                    Property="BorderThickness"
                    Value="1,0,1,1" />

            <Setter TargetName="contentPanel"
                    Property="Margin"
                    Value="1,1,-1,0" />

            <Setter TargetName="bottomBorder"
                    Property="Visibility"
                    Value="Hidden" />

            <Setter TargetName="isPressedLightInnerHighlight"
                    Property="BorderBrush"
                    Value="{StaticResource headerPressedLightInnerHighlightBrush}" />

            <Setter TargetName="isPressedDarkInnerHighlight"
                    Property="BorderBrush"
                    Value="{StaticResource headerPressedDarkInnerHighlightBrush}" />

         </Trigger>

         <!-- The following 2 triggers allow to display the appropriate Sort Glyph
              depending on the ParentColumn's SortDirection. -->

         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=SortDirection}"
                      Value="Ascending">

            <Setter TargetName="sortGlyphPresenter"
                    Property="Visibility"
                    Value="Visible" />

         </DataTrigger>

         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=SortDirection}"
                      Value="Descending">

            <Setter TargetName="sortGlyphPresenter"
                    Property="ContentPresenter.ContentTemplate"
                    Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).DescendingSortGlyph}" />

            <Setter TargetName="sortGlyphPresenter"
                    Property="Visibility"
                    Value="Visible" />

         </DataTrigger>

      </ControlTemplate.Triggers>

   </ControlTemplate>

   <!--**************************
    * TEMPLATE: GroupHeaderControl (When top level sticky)
    ************************** -->
   <ControlTemplate x:Key="tableflowViewGroupHeaderTopLevelStickyControlTemplate"
                    TargetType="local:GroupHeaderControl">

      <!-- Using this decorator will prevent the GroupHeaderControl of exceeding the width 
           defined by the grid's column. -->
      <views:PassiveLayoutDecorator Axis="Horizontal">
         <!-- This DockPanel is used to layout the GroupLevelIndicatorPane placeholder and the GroupHeaderControl Content. -->
         <DockPanel>

            <!-- GroupLevelIndicatorPane is a placeholder for individual GroupLevelIndicator elements that are added
              whenever this GroupHeaderControl is part of a group. -->
            <local:HierarchicalGroupLevelIndicatorPane DockPanel.Dock="Left" />
            <local:GroupLevelIndicatorPane DockPanel.Dock="Left"
                                           Indented="False"
                                           local:GroupLevelIndicatorPane.GroupLevel="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:GroupLevelIndicatorPane.GroupLevel), Converter={StaticResource groupHeaderControlGroupLevelConverter}, ConverterParameter=-1}" />

            <Grid>
               <Border BorderThickness="0,1,0,1">
                  <Border.BorderBrush>
                     <LinearGradientBrush StartPoint="0.5,1"
                                          EndPoint="0.5,0">
                        <GradientStop Color="#B9BBCA"
                                      Offset="0" />
                        <GradientStop Color="#DFDFDF"
                                      Offset="1" />
                     </LinearGradientBrush>
                  </Border.BorderBrush>
                  <Border.Background>
                     <LinearGradientBrush StartPoint="0.5,0"
                                          EndPoint="0.5,1">
                        <GradientStop Color="#D0D1D2"
                                      Offset="1" />
                        <GradientStop Color="#E8E9EB"
                                      Offset="0" />
                     </LinearGradientBrush>
                  </Border.Background>
               </Border>
               <!-- Main Border for the GroupHeaderControl. It is Focusable to make the InputBindings work. -->
               <Border x:Name="mainBorder"
                       Background="Transparent"
                       BorderBrush="{TemplateBinding BorderBrush}"
                       BorderThickness="{TemplateBinding BorderThickness}"
                       Padding="{TemplateBinding Padding}"
                       Focusable="True"
                       FocusVisualStyle="{TemplateBinding FocusVisualStyle}">

                  <!-- Define all the standard InputBindings for a GroupHeaderControl. -->
                  <Border.InputBindings>
                     <KeyBinding Command="{x:Static local:DataGridCommands.ToggleGroupExpansion}"
                                 Key="Space" />

                     <KeyBinding Command="{x:Static local:DataGridCommands.ExpandGroup}"
                                 Key="Right" />

                     <KeyBinding Command="{x:Static local:DataGridCommands.ExpandGroup}"
                                 Key="Add" />

                     <KeyBinding Command="{x:Static local:DataGridCommands.CollapseGroup}"
                                 Key="Left" />

                     <KeyBinding Command="{x:Static local:DataGridCommands.CollapseGroup}"
                                 Key="Subtract" />

                     <MouseBinding Command="{x:Static local:DataGridCommands.ToggleGroupExpansion}"
                                   MouseAction="LeftDoubleClick" />

                  </Border.InputBindings>

                  <DockPanel>

                     <!-- ToggleButton that is used to expand/collapse the group. -->
                     <ToggleButton DockPanel.Dock="Left"
                                   OverridesDefaultStyle="True"
                                   Template="{StaticResource groupExpanderToggleButtonTemplate}"
                                   VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                   Focusable="False"
                                   IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Group.IsExpanded}" />

                     <!-- ContentPresenter in charge of displaying this GroupHeaderControl's Content, which is
                    a Group by default. -->
                     <ContentPresenter DockPanel.Dock="Left"
                                       Margin="3,0,0,0"
                                       Content="{TemplateBinding Content}"
                                       ContentTemplate="{TemplateBinding ContentTemplate}"
                                       ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                       VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                  </DockPanel>
               </Border>
            </Grid>
         </DockPanel>
      </views:PassiveLayoutDecorator>

      <ControlTemplate.Triggers>
         <Trigger Property="local:DataGridControl.NavigationBehavior"
                  Value="None">
            <Setter TargetName="mainBorder"
                    Property="Focusable"
                    Value="False" />
         </Trigger>
      </ControlTemplate.Triggers>

   </ControlTemplate>

   <!-- =================================================================== -->
   <!-- Styles required by some grid elements                               -->
   <!-- =================================================================== -->

   <!--**************************
    * STYLE: CellErrorStyle 
    ************************** -->
   <Style x:Key="cellErrorStyle"
          TargetType="local:Cell">

      <Setter Property="Background"
              Value="{StaticResource errorBackgroundBrush}" />

      <Setter Property="Foreground"
              Value="{StaticResource errorForegroundBrush}" />

      <Setter Property="ToolTip"
              Value="{Binding RelativeSource={RelativeSource Self},Path=ValidationError.ErrorContent}" />

      <Style.Triggers>
         <Trigger Property="IsValidationErrorRestrictive"
                  Value="True">
            <Setter Property="Background"
                    Value="{StaticResource errorBackgroundBrush}" />

         </Trigger>

         <Trigger Property="IsValidationErrorRestrictive"
                  Value="False">

            <Setter Property="Foreground"
                    Value="{StaticResource warningForegroundBrush}" />

            <Setter Property="Background"
                    Value="{StaticResource warningBackgroundBrush}" />

         </Trigger>
      </Style.Triggers>

   </Style>

   <!-- =================================================================== -->
   <!-- Keyed Styles of grid elements                                       -->
   <!-- =================================================================== -->

   <!--**************************
    * STYLE: DataGridControl 
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicGridControlStyle"
          TargetType="local:DataGridControl">

      <Setter Property="BorderBrush"
              Value="{StaticResource gridControlBorderBrush}" />

      <Setter Property="BorderThickness"
              Value="1" />

      <Setter Property="Background"
              Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />

      <Setter Property="Foreground"
              Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />

      <!-- This is required to display gridlines of uniform thickness -->
      <Setter Property="SnapsToDevicePixels"
              Value="True" />

      <Setter Property="CellErrorStyle"
              Value="{StaticResource cellErrorStyle}" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewDataGridControlTemplate}" />

   </Style>

   <!--**************************
    * STYLE: DataGridControl (with hosted controls theming)
    ************************** -->
   <Style x:Key="tableflowViewForcedLunaMetallicGridControlStyle"
          BasedOn="{StaticResource tableflowViewLunaMetallicGridControlStyle}"
          TargetType="local:DataGridControl">

      <Style.Resources>
         <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
               <markup:FrameworkThemeResourceDictionary Source="/PresentationFramework.Luna;V4.0.0.0;31bf3856ad364e35;component\themes/luna.metallic.xaml" />
            </ResourceDictionary.MergedDictionaries>
         </ResourceDictionary>
      </Style.Resources>

   </Style>

   <!--**************************
    * STYLE: RowSelectorPane
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicRowSelectorPaneStyle"
          TargetType="local:RowSelectorPane">

      <Setter Property="Background"
              Value="{StaticResource headerBackgroundBrush}" />

      <Setter Property="TextElement.Foreground"
              Value="{StaticResource headerForegroundBrush}" />

   </Style>

   <!--**************************
    * STYLE: RowSelector 
    ************************** -->
   <conv:TypeToBooleanConverter x:Key="rowTypeConverter" />
   <Style x:Key="tableflowViewLunaMetallicRowSelectorStyle"
          TargetType="local:RowSelector">

      <!-- Set the RowSelector's background to Transparent to make it hit-testable
           while preserving the background drawn by the underlying RowSelectorPane. -->
      <Setter Property="Background"
              Value="Transparent" />

      <Setter Property="HorizontalContentAlignment"
              Value="Center" />

      <Setter Property="VerticalContentAlignment"
              Value="Top" />

      <Setter Property="Padding"
              Value="2" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewRowSelectorTemplate}" />

      <Style.Triggers>

         <!-- The DataContext of a RowSelector is always set to its corresponding
              Row/item. This is why we use DataTriggers with no explicit Binding Source
              when we want to react to properties of the Row/item. -->

         <!-- When the Row is Current, display the current glyph in the RowSelector -->
         <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
               <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsCurrent}"
                          Value="True" />
            </MultiDataTrigger.Conditions>
            <Setter Property="ContentTemplate"
                    Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).CurrentItemGlyph}" />
         </MultiDataTrigger>

         <!-- When the Row is being edited, display the appropriate glyph in the RowSelector. -->
         <Trigger Property="IsBeingEdited"
                  Value="True">
            <Setter Property="ContentTemplate"
                    Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).EditingRowGlyph}" />

         </Trigger>

         <!-- When the Row has a validation error, display the appropriate glyph in the RowSelector. -->
         <Trigger Property="HasValidationError"
                  Value="True">
            <Setter Property="ContentTemplate"
                    Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).ValidationErrorGlyph}" />
         </Trigger>

      </Style.Triggers>

   </Style>

   <!--**************************
    * STYLE: Row
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicRowStyle"
          TargetType="local:Row">

      <Setter Property="FocusVisualStyle"
              Value="{StaticResource tableflowViewRowFocusVisualStyle}" />

      <Setter Property="SelectionBackground"
              Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />

      <Setter Property="SelectionForeground"
              Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />

      <Setter Property="InactiveSelectionBackground"
              Value="{DynamicResource {x:Static SystemColors.InactiveCaptionBrushKey}}" />

      <Setter Property="InactiveSelectionForeground"
              Value="{DynamicResource {x:Static SystemColors.InactiveCaptionTextBrushKey}}" />

      <!-- The Row is responsible for drawing the horizontal gridlines. It draws only its top gridline,
           assuming that the bottom gridline will be drawn by its following row/element -->

      <Setter Property="BorderThickness"
              Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).HorizontalGridLineThickness, Converter={StaticResource thicknessConverter}, ConverterParameter='Top'}" />

      <Setter Property="BorderBrush"
              Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).HorizontalGridLineBrush}" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewRowTemplate}" />

      <Setter Property="Background"
              Value="Transparent" />

      <Setter Property="Foreground"
              Value="{Binding RelativeSource={RelativeSource Self}, Path=ParentForeground}" />

      <Style.Triggers>
         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(views:ViewBase.IsLastItem)}"
                      Value="True">
            <Setter Property="BorderThickness"
                    Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).HorizontalGridLineThickness, Converter={StaticResource thicknessConverter}, ConverterParameter='Top, Bottom'}" />
         </DataTrigger>

         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.HasExpandedDetails)}"
                      Value="True">
            <Setter Property="BorderThickness"
                    Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).HorizontalGridLineThickness, Converter={StaticResource thicknessConverter}, ConverterParameter='Top, Bottom'}" />

         </DataTrigger>

         <!-- Enabled/Disabled Odd datarow style alternation -->
         <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
               <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).IsAlternatingRowStyleEnabled}"
                          Value="True" />
               <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridVirtualizingPanel.ItemIndex), Converter={x:Static conv:IndexToOddConverter.Singleton}}"
                          Value="True" />
            </MultiDataTrigger.Conditions>

            <Setter Property="Background"
                    Value="#F2F1E7" />

         </MultiDataTrigger>
      </Style.Triggers>

   </Style>

   <!--**************************
    * STYLE: DataRow 
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicDataRowStyle"
          TargetType="local:DataRow"
          BasedOn="{StaticResource tableflowViewLunaMetallicRowStyle}">
   </Style>


   <!--**************************
    * STYLE: ColumnManagerRow 
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicColumnManagerRowStyle"
          TargetType="local:ColumnManagerRow"
          BasedOn="{StaticResource tableflowViewLunaMetallicRowStyle}">

      <!-- Use a different background and foreground than the base Row style. -->
      <Setter Property="Background"
              Value="{StaticResource headerBackgroundBrush}" />

      <Setter Property="Foreground"
              Value="{StaticResource headerForegroundBrush}" />

      <Setter Property="local:RowSelector.Visible"
              Value="False" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewColumnManagerRowTemplate}" />

      <Style.Triggers>
         <Trigger Property="local:GroupLevelIndicatorPane.GroupLevel"
                  Value="-1">
            <!-- We don't want to display the Group Margins for the ColumnManagerRow. -->
            <Setter Property="local:GroupLevelIndicatorPane.ShowIndicators"
                    Value="False" />
         </Trigger>

      </Style.Triggers>

   </Style>

   <!--**************************
    * STYLE: Cell Style
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicCellStyle"
          TargetType="local:Cell">

      <Setter Property="CurrentBackground"
              Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />

      <Setter Property="CurrentForeground"
              Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />

      <Setter Property="SelectionBackground"
              Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />

      <Setter Property="SelectionForeground"
              Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />

      <Setter Property="InactiveSelectionBackground"
              Value="{DynamicResource {x:Static SystemColors.InactiveCaptionBrushKey}}" />

      <Setter Property="InactiveSelectionForeground"
              Value="{DynamicResource {x:Static SystemColors.InactiveCaptionTextBrushKey}}" />

      <!-- Set the Cell's background to Transparent to make it hit-testable
           while preserving the background drawn by the underlying Row. -->
      <Setter Property="Background"
              Value="Transparent" />

      <Setter Property="Foreground"
              Value="{Binding RelativeSource={RelativeSource Self}, Path=ParentForeground}" />

      <!-- In TableflowView, each Cell has the same width as its ParentColum's ActualWidth -->
      <Setter Property="Width"
              Value="{Binding RelativeSource={RelativeSource Self}, Path=ParentColumn.ActualWidth}" />

      <Setter Property="Padding"
              Value="{StaticResource cellPadding}" />

      <Setter Property="HorizontalContentAlignment"
              Value="{Binding RelativeSource={RelativeSource Self}, Path=ParentColumn.CellHorizontalContentAlignment, FallbackValue=Stretch}" />

      <Setter Property="VerticalContentAlignment"
              Value="{Binding RelativeSource={RelativeSource Self}, Path=ParentColumn.CellVerticalContentAlignment, FallbackValue=Stretch}" />

      <!-- The Cell is responsible for drawing the vertical gridlines. It draws only its right gridline, 
           assuming that the left gridline will have been drawn by its preceding cell -->

      <Setter Property="BorderThickness"
              Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).VerticalGridLineThickness, Converter={StaticResource thicknessConverter}, ConverterParameter='Right'}" />

      <Setter Property="BorderBrush"
              Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).VerticalGridLineBrush}" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewCellTemplate}" />

   </Style>

   <!--**************************
    * STYLE: DataCell
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicDataCellStyle"
          TargetType="local:DataCell"
          BasedOn="{StaticResource tableflowViewLunaMetallicCellStyle}" />

   <!--**************************
    * STYLE: ColumnManagerCell 
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicColumnManagerCellStyle"
          TargetType="local:ColumnManagerCell">

      <!-- Set the Cell's background to Transparent to make it hit-testable
           while preserving the background drawn by the underlying Row. -->
      <Setter Property="Background"
              Value="Transparent" />

      <!-- In TableflowView, each Cell has the same width as its ParentColum's ActualWidth -->
      <Setter Property="Width"
              Value="{Binding RelativeSource={RelativeSource Self},Path=ParentColumn.ActualWidth}" />

      <Setter Property="Padding"
              Value="{StaticResource columnManagerCellPadding}" />

      <Setter Property="HorizontalContentAlignment"
              Value="{Binding RelativeSource={RelativeSource Self}, Path=ParentColumn.CellHorizontalContentAlignment, FallbackValue=Stretch}" />

      <Setter Property="VerticalContentAlignment"
              Value="{Binding RelativeSource={RelativeSource Self}, Path=ParentColumn.CellVerticalContentAlignment, FallbackValue=Stretch}" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewColumnManagerCellTemplate}" />

   </Style>

   <!--**************************
    * STYLE: GroupByControl 
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicGroupByControlStyle"
          TargetType="local:GroupByControl">

      <!-- If we don't specify a MinHeight, the default "size-to-content" behavior will arrange 
           the control with a Height of 0, which makes it invisible and unusable.
           In a typical TableflowView, a height of at least 25 is appropriate for the GroupByControl. -->
      <Setter Property="MinHeight"
              Value="25" />

      <Setter Property="Background"
              Value="{StaticResource groupByControlBackgroundBrush}" />

      <Setter Property="Foreground"
              Value="{StaticResource groupByControlForegroundBrush}" />

      <Setter Property="Padding"
              Value="8" />

      <Setter Property="BorderBrush"
              Value="{StaticResource gridLineBrush}" />

      <Setter Property="BorderThickness"
              Value="1,1,1,0" />

      <Setter Property="local:RowSelector.Visible"
              Value="False" />

      <Setter Property="views:TableView.CanScrollHorizontally"
              Value="False" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewGroupByControlTemplate}" />

   </Style>

   <!--**************************
    * STYLE: GroupByItem
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicGroupByItemStyle"
          TargetType="local:GroupByItem">

      <Setter Property="Background"
              Value="{StaticResource headerBackgroundBrush}" />

      <Setter Property="Foreground"
              Value="{StaticResource headerForegroundBrush}" />

      <Setter Property="Padding"
              Value="{StaticResource cellPadding}" />

      <Setter Property="BorderBrush"
              Value="{StaticResource gridLineBrush}" />

      <Setter Property="BorderThickness"
              Value="1" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewGroupByItemTemplate}" />

   </Style>

   <!--**************************
    * STYLE: GroupHeaderControl 
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicGroupHeaderControlStyle"
          TargetType="local:GroupHeaderControl">

      <Setter Property="Background"
              Value="{StaticResource headerBackgroundBrush}" />

      <Setter Property="Foreground"
              Value="{StaticResource headerForegroundBrush}" />

      <Setter Property="BorderBrush"
              Value="{StaticResource gridLineBrush}" />

      <Setter Property="SelectionBackground"
              Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />

      <Setter Property="SelectionForeground"
              Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />

      <Setter Property="InactiveSelectionBackground"
              Value="{DynamicResource {x:Static SystemColors.InactiveCaptionBrushKey}}" />

      <Setter Property="InactiveSelectionForeground"
              Value="{DynamicResource {x:Static SystemColors.InactiveCaptionTextBrushKey}}" />

      <Setter Property="views:TableView.CanScrollHorizontally"
              Value="False" />

      <Setter Property="BorderThickness"
              Value="0,1,1,0" />

      <Setter Property="Padding"
              Value="{StaticResource cellPadding}" />

      <Setter Property="VerticalContentAlignment"
              Value="Center" />

      <!-- The GroupHeaderControl itself must not be focusable. The main Border inside its Template will
           be made Focusable because it is holding the various InputBindings that make the
           GroupHeaderControl work. -->
      <Setter Property="Focusable"
              Value="False" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewGroupHeaderControlTemplate}" />

      <Style.Triggers>
         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(views:ViewBase.IsLastItem)}"
                      Value="True">

            <Setter Property="BorderThickness"
                    Value="0,1,1,1" />
         </DataTrigger>

         <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
               <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Content.IsBottomLevel}"
                          Value="False" />
               <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Content.Level}"
                          Value="0" />
               <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).AreGroupHeadersSticky}"
                          Value="True" />
               <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).AreGroupsFlattened}"
                          Value="True" />
            </MultiDataTrigger.Conditions>

            <Setter Property="Template"
                    Value="{StaticResource tableflowViewGroupHeaderTopLevelStickyControlTemplate}" />

         </MultiDataTrigger>

      </Style.Triggers>

   </Style>

   <!--**************************
    * STYLE: GroupLevelIndicator
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicGroupLevelIndicatorStyle"
          TargetType="local:GroupLevelIndicator">

      <Setter Property="Background"
              Value="{StaticResource headerBackgroundBrush}" />

      <Setter Property="Foreground"
              Value="{StaticResource headerForegroundBrush}" />

      <Setter Property="BorderBrush"
              Value="{StaticResource gridLineBrush}" />

      <Setter Property="BorderThickness"
              Value="0,0,1,0" />

      <Setter Property="Width"
              Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).GroupLevelIndicatorWidth}" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewGroupLevelIndicatorTemplate}" />

   </Style>

   <!--**************************
    * STYLE: DetailIndicator
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicDetailIndicatorStyle"
          TargetType="local:DetailIndicator">

      <Setter Property="Background"
              Value="{x:Null}" />

      <Setter Property="Width"
              Value="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).DetailIndicatorWidth}" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewDetailIndicatorTemplate}" />

   </Style>

   <!--**************************
    * STYLE: GroupLevelIndicatorPane
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicGroupLevelIndicatorPaneStyle"
          TargetType="local:GroupLevelIndicatorPane">

      <Setter Property="Template"
              Value="{StaticResource tableflowViewGroupLevelIndicatorPaneTemplate}" />

      <Setter Property="BorderBrush"
              Value="{StaticResource gridLineBrush}" />

      <Style.Triggers>
         <MultiTrigger>
            <MultiTrigger.Conditions>
               <Condition Property="IsLeaf"
                          Value="False" />
               <Condition Property="views:ViewBase.IsLastItem"
                          Value="True" />
            </MultiTrigger.Conditions>

            <Setter Property="Margin"
                    Value="0,0,0,-5" />
         </MultiTrigger>

      </Style.Triggers>
   </Style>

   <!--**************************
    * STYLE: HierarchicalGroupLevelIndicatorPane
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicHierarchicalGroupLevelIndicatorPaneStyle"
          TargetType="local:HierarchicalGroupLevelIndicatorPane">

      <Setter Property="Template"
              Value="{StaticResource tableflowViewHierarchicalGroupLevelIndicatorPaneTemplate}" />

      <Setter Property="local:GroupLevelIndicatorPane.ShowIndicators"
              Value="True" />

      <Setter Property="local:GroupLevelIndicatorPane.ShowVerticalBorder"
              Value="True" />

      <Style.Triggers>
         <Trigger Property="local:GroupLevelIndicatorPane.GroupLevel"
                  Value="-1">

            <!-- Stop the propagation of the value set by the default style trigger of
                 the ColumnManagerRow -->
            <Setter Property="local:GroupLevelIndicatorPane.ShowIndicators"
                    Value="True" />

         </Trigger>
      </Style.Triggers>
   </Style>

   <!--**************************
    * STYLE: HierarchicalGroupByControlNode
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicHierarchicalGroupByControlNodeStyle"
          TargetType="local:HierarchicalGroupByControlNode">

      <Setter Property="StairHeight"
              Value="0" />

      <Setter Property="ConnectionLineOffset"
              Value="0" />

      <Setter Property="Focusable"
              Value="False" />

      <Setter Property="ConnectionLineAlignment"
              Value="CenterToCenter" />

      <Setter Property="Margin"
              Value="0,5,0,5" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewHierarchicalGroupByControlNodeTemplate}" />

   </Style>

   <!--**************************
    * STYLE: HierarchicalGroupByControl
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicHierarchicalGroupByControlStyle"
          TargetType="local:HierarchicalGroupByControl">

      <Setter Property="Background"
              Value="{StaticResource groupByControlBackgroundBrush}" />

      <Setter Property="StairHeight"
              Value="0" />

      <Setter Property="ConnectionLineOffset"
              Value="0" />

      <Setter Property="ConnectionLineAlignment"
              Value="CenterToCenter" />

      <Setter Property="local:RowSelector.Visible"
              Value="False" />

      <Setter Property="views:TableView.CanScrollHorizontally"
              Value="False" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewCommonHierarchicalGroupByControlTemplate}" />

      <Style.Triggers>

         <!-- We use the old GroupByControl Template if there are no Details in the DataGridControl.ItemsSource -->
         <MultiDataTrigger>
            <MultiDataTrigger.Conditions>

               <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).HasDetails}"
                          Value="False" />

               <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(local:DataGridControl.DataGridContext).ParentDataGridContext, Converter={StaticResource nullToBooleanConverter}}"
                          Value="True" />

            </MultiDataTrigger.Conditions>

            <Setter Property="Template"
                    Value="{StaticResource tableflowViewCommonHierarchicalGroupByControlOldGroupByControlTemplate}" />

         </MultiDataTrigger>

      </Style.Triggers>

   </Style>

   <!--**************************
    * STYLE: HierarchicalGroupByItem
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicHierarchicalGroupByItemStyle"
          TargetType="local:HierarchicalGroupByItem">

      <Setter Property="Background"
              Value="{StaticResource headerBackgroundBrush}" />

      <Setter Property="Foreground"
              Value="{StaticResource headerForegroundBrush}" />

      <Setter Property="Padding"
              Value="{StaticResource cellPadding}" />

      <Setter Property="BorderBrush"
              Value="{StaticResource gridLineBrush}" />

      <Setter Property="BorderThickness"
              Value="1" />

      <Setter Property="Margin"
              Value="4,0,4,0" />

      <Setter Property="Template"
              Value="{StaticResource tableflowViewHierarchicalGroupByItemTemplate}" />

   </Style>

   <!--**************************
    * STYLE: ScrollTip
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicScrollTipStyle"
          TargetType="local:ScrollTip">

      <Setter Property="Template"
              Value="{StaticResource scrollTipTemplate}" />

      <Setter Property="Background">
         <Setter.Value>
            <LinearGradientBrush StartPoint="0.5,1"
                                 EndPoint="0.5,0">
               <GradientStop Color="#FFD7D7E3"
                             Offset="0" />

               <GradientStop Color="#FFFEFEFE"
                             Offset="1" />
            </LinearGradientBrush>
         </Setter.Value>
      </Setter>

      <Setter Property="BorderBrush"
              Value="#FF666666" />

      <Setter Property="TextElement.Foreground"
              Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />

      <Setter Property="VerticalAlignment"
              Value="Center" />

      <Setter Property="HorizontalAlignment"
              Value="Right" />

   </Style>

   <!--**************************
    * STYLE: GroupNavigationControl
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicGroupNavigationControlStyle"
          TargetType="local:GroupNavigationControl">
      <Setter Property="Template"
              Value="{StaticResource tableflowViewGroupNavigationControlTemplate}" />
   </Style>

   <!--**************************
    * STYLE: GroupNavigationControlItem
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicGroupNavigationControlItemStyle"
          TargetType="{x:Type local:GroupNavigationControlItem}">

      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:GroupNavigationControlItem}">
               <Grid SnapsToDevicePixels="true">
                  <Border x:Name="Border"
                          Background="Transparent" />
                  <Border Margin="2">
                     <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                       VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                  </Border>
               </Grid>
               <ControlTemplate.Triggers>

                  <!-- Change IsSelected SelectedBackgroundBrush to set the selection color for the items -->
                  <Trigger Property="IsMouseOver"
                           Value="true">
                     <Setter Property="Background"
                             TargetName="Border"
                             Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />

                     <Setter Property="Foreground"
                             Value="Black" />
                  </Trigger>

                  <Trigger Property="IsEnabled"
                           Value="false">
                     <Setter Property="Foreground"
                             Value="Gray" />
                  </Trigger>
               </ControlTemplate.Triggers>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <!--**************************
    * STYLE: GroupNavigationButton
    ************************** -->
   <Style x:Key="tableflowViewLunaMetallicGroupNavigationButtonStyle"
          TargetType="local:GroupNavigationButton">
      <Setter Property="Template"
              Value="{StaticResource tableflowViewGroupNavigationButtonTemplate}" />
   </Style>

   <!-- =================================================================== -->
   <!-- Default values for the View                                         -->
   <!-- =================================================================== -->

   <Style x:Key="tableflowViewLunaMetallicDefaultValues"
          TargetType="views:TableflowView">

      <Setter Property="HorizontalGridLineBrush"
              Value="{StaticResource gridLineBrush}" />

      <Setter Property="HorizontalGridLineThickness"
              Value="1" />

      <Setter Property="VerticalGridLineBrush"
              Value="{StaticResource gridLineBrush}" />

      <Setter Property="VerticalGridLineThickness"
              Value="1" />

      <Setter Property="GroupLevelIndicatorWidth"
              Value="17" />

      <Setter Property="DetailIndicatorWidth"
              Value="34" />

      <Setter Property="DefaultDropMarkPen"
              Value="{StaticResource dropMarkPen}" />

      <!-- Those glyphs are null by default on ViewBase, so every Theme should define
           and set their own custom glyphs. -->

      <Setter Property="AscendingSortGlyph"
              Value="{StaticResource ascendingSortGlyph}" />

      <Setter Property="DescendingSortGlyph"
              Value="{StaticResource descendingSortGlyph}" />

      <Setter Property="ExpandGroupGlyph"
              Value="{StaticResource expandGroupGlyph}" />

      <Setter Property="CollapseGroupGlyph"
              Value="{StaticResource collapseGroupGlyph}" />

      <Setter Property="CurrentItemGlyph"
              Value="{StaticResource currentItemGlyph}" />

      <Setter Property="EditingRowGlyph"
              Value="{StaticResource editingRowGlyph}" />

      <Setter Property="ValidationErrorGlyph"
              Value="{StaticResource validationErrorGlyph}" />

      <Setter Property="ConnectionStateLoadingGlyph"
              Value="{StaticResource connectionStateLoadingGlyph}" />

      <Setter Property="ConnectionStateCommittingGlyph"
              Value="{StaticResource connectionStateLoadingGlyph}" />

      <Setter Property="ConnectionStateErrorGlyph"
              Value="{StaticResource connectionStateErrorGlyph}" />

   </Style>

   <!-- =================================================================== -->
   <!-- DefaultStyleKey declarations                                        -->
   <!-- =================================================================== -->

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme}"
          TargetType="views:TableflowView"
          BasedOn="{StaticResource tableflowViewLunaMetallicDefaultValues}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:DataGridControl}"
          TargetType="local:DataGridControl"
          BasedOn="{StaticResource tableflowViewForcedLunaMetallicGridControlStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:RowSelectorPane}"
          TargetType="local:RowSelectorPane"
          BasedOn="{StaticResource tableflowViewLunaMetallicRowSelectorPaneStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:RowSelector}"
          TargetType="local:RowSelector"
          BasedOn="{StaticResource tableflowViewLunaMetallicRowSelectorStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:Row}"
          TargetType="local:Row"
          BasedOn="{StaticResource tableflowViewLunaMetallicRowStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:DataRow}"
          TargetType="local:DataRow"
          BasedOn="{StaticResource tableflowViewLunaMetallicDataRowStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:ColumnManagerRow}"
          TargetType="local:ColumnManagerRow"
          BasedOn="{StaticResource tableflowViewLunaMetallicColumnManagerRowStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:Cell}"
          TargetType="local:Cell"
          BasedOn="{StaticResource tableflowViewLunaMetallicCellStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:DataCell}"
          TargetType="local:DataCell"
          BasedOn="{StaticResource tableflowViewLunaMetallicDataCellStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:ColumnManagerCell}"
          TargetType="local:ColumnManagerCell"
          BasedOn="{StaticResource tableflowViewLunaMetallicColumnManagerCellStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:GroupByControl}"
          TargetType="local:GroupByControl"
          BasedOn="{StaticResource tableflowViewLunaMetallicGroupByControlStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:GroupByItem}"
          TargetType="local:GroupByItem"
          BasedOn="{StaticResource tableflowViewLunaMetallicGroupByItemStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:GroupHeaderControl}"
          TargetType="local:GroupHeaderControl"
          BasedOn="{StaticResource tableflowViewLunaMetallicGroupHeaderControlStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:GroupLevelIndicator}"
          TargetType="local:GroupLevelIndicator"
          BasedOn="{StaticResource tableflowViewLunaMetallicGroupLevelIndicatorStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:DetailIndicator}"
          TargetType="local:DetailIndicator"
          BasedOn="{StaticResource tableflowViewLunaMetallicDetailIndicatorStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:DetailConfiguration}"
          TargetType="local:DetailConfiguration"
          BasedOn="{StaticResource tableflowViewLunaMetallicDetailIndicatorStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:GroupLevelIndicatorPane}"
          TargetType="local:GroupLevelIndicatorPane"
          BasedOn="{StaticResource tableflowViewLunaMetallicGroupLevelIndicatorPaneStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:HierarchicalGroupLevelIndicatorPane}"
          TargetType="local:HierarchicalGroupLevelIndicatorPane"
          BasedOn="{StaticResource tableflowViewLunaMetallicHierarchicalGroupLevelIndicatorPaneStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:ScrollTip}"
          TargetType="local:ScrollTip"
          BasedOn="{StaticResource tableflowViewLunaMetallicScrollTipStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:HierarchicalGroupByControlNode}"
          TargetType="local:HierarchicalGroupByControlNode"
          BasedOn="{StaticResource tableflowViewLunaMetallicHierarchicalGroupByControlNodeStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:HierarchicalGroupByControl}"
          TargetType="local:HierarchicalGroupByControl"
          BasedOn="{StaticResource tableflowViewLunaMetallicHierarchicalGroupByControlStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:HierarchicalGroupByItem}"
          TargetType="local:HierarchicalGroupByItem"
          BasedOn="{StaticResource tableflowViewLunaMetallicHierarchicalGroupByItemStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:GroupNavigationButton}"
          TargetType="local:GroupNavigationButton"
          BasedOn="{StaticResource tableflowViewLunaMetallicGroupNavigationButtonStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:GroupNavigationControl}"
          TargetType="local:GroupNavigationControl"
          BasedOn="{StaticResource tableflowViewLunaMetallicGroupNavigationControlStyle}" />

   <Style x:Key="{markup:ThemeKey TargetViewType=views:TableflowView, ThemeType=views:LunaMetallicTheme, TargetElementType=local:GroupNavigationControlItem}"
          TargetType="local:GroupNavigationControlItem"
          BasedOn="{StaticResource tableflowViewLunaMetallicGroupNavigationControlItemStyle}" />
</ResourceDictionary>
